package htmlmake;

import java.io.*;
import java.util.*;

/**
 *
 * @author eric2ai
 */

 public class HtDir {
	//public File 		file;
			  String		dir;
	public String		name;
	public int			score;
	public int			weight;
			  int			lead;
    public boolean hasThumb;

	//
	HtDir(File f){
		//file = f;
		dir = f.getName();
		int i = dir.lastIndexOf('.');
		if ( i == -1 ){
			name = dir;
			score = 0;
		}else {
			name = dir.substring(0, i);
			try {
			score = Integer.parseInt(dir.substring(i+1, dir.length()));
			} catch (NumberFormatException e){
			}
		}
		
		String s = name;
		CharSequence target = ",";
		CharSequence replacement = "<br>";
		
		name = s.replace(target, replacement);

        /*
		FilenameFilter filter = new FilenameFilter() {
			public boolean accept(File dir, String name) {
				return name.compareToIgnoreCase("_thumb.jpg")!=0;
			}
        };

        File[] files = f.listFiles(filter);
        */

        File[] files = f.listFiles();
        weight = files.length;
        hasThumb = false;

        for (int j=0; j<files.length; j++){
            if ( files[j].getName().compareToIgnoreCase("_thumb.jpg") ==0 ){
                weight--;
                hasThumb=true;
                break;
            }
        }
        
		lead = 0;
	}
	
	//
	char getNameType(){
		char c = Character.toUpperCase(name.charAt(0));
		if ( Character.isLetter(c) ) return c;
		else return '@';
	}
	
	//
	char getScoreType(){
		return Character.forDigit(score, 10);
	}
	
	//
	String getNameTypeString(){
		return ""+getNameType();
	}
	
	//
	String getScoreTypeString(){
	/*
		String s = "";
		for (int i=0; i<score; i++){
			//s += "*";
			s += "<img border=0 src=\"star.gif\"/>";
		}
		return s;
	*/
		return "<img border=0 src=\"star" + score + "s.gif\"/>";
	}
	
	//
	String getNameFileName()
	{
		return "$_" + getNameType() + ".htm";
	}
	
	//
	String getScoreFileName()
	{
		return "$_" + score + ".htm";
	}
}